package week2;

import java.util.Scanner;

public class Day5 {

    //1.游游的水果大礼包
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextInt()) { // 注意 while 处理多个 case
            int n = in.nextInt();
            int m = in.nextInt();
            int a = in.nextInt();
            int b = in.nextInt();
            int max=0;
            int ret=1;
            for(int i=0;i<Math.min(n/2,m);i++) {
                ret = i*a;
                n -= i*2;
                m -= i*1;
                ret += b * Math.min(n,m/2);
                max=Math.max(max,ret);
            }
            System.out.println(max);
        }
    }

    //2.买卖股票的最好时机(二)
    public static void main2(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextInt()) { // 注意 while 处理多个 case
            int n = in.nextInt();
            int[] price = new int[n];
            for(int i=0;i<n;i++) price[i]=in.nextInt();
            int[] f = new int[n];//持有股票的最大利润
            int[] g = new int[n];//不持股票的最大利润
            if(n>0)  f[0]=-price[0];
            for(int i=1;i<n;i++) {
                f[i]=Math.max(f[i-1],g[i-1]-price[i]);
                g[i]=Math.max(g[i-1],f[i-1]+price[i]);
            }
            System.out.println(g[n-1]);
        }
    }

    //3.倒置字符串
    public static void main3(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextLine()) { // 注意 while 处理多个 case
            String s = in.nextLine();
            StringBuilder sb = new StringBuilder();
            String[] tmp = s.split(" ");
            for(int i=tmp.length-1;i>=0;i--) {
                String ch = tmp[i];
                if(i!=0) sb.append(ch+" ");
                else sb.append(ch);
            }
            System.out.println(sb);
        }
    }
}
